package com.safe.first.common.constants;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.safe.first.common.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;

/**
 * @author Mickey
 * @since 2021/11/2
 */
@Getter
@AllArgsConstructor
public enum LoginEnum implements BaseEnum<LoginEnum> {
    NOT_LOG_IN(401, "未登陆"),
    NOT_CERTIFICATION(410, "未实名认证"),
    NONAGE(411, "未满18岁"),
    PERMISSION_DENIED(403, "权限不足"),
    USER_LOCK(405, "用户锁定"),
    ;

    private final Integer code;
    private final String name;

    public static LoginEnum of(Integer code) {
        return Optional.ofNullable(BaseEnum.parseByCode(LoginEnum.class, code)).orElseThrow(() -> new BizException(CodeEnum.FAIL));
    }

    @JsonCreator
    public static LoginEnum create(EnumDict type) {
        return of(type.getCode());
    }
}
